<template>
  <div>
    <span class="el-menu__title">问题记录</span>
    <el-form ref="User" :model="User" label-width="80px"
             :rules="questrules" label-position="right" style="margin-top: 15px">
      <el-form-item label="问题描述" prop="descri">
        <el-col :span="4">
          <el-input type="textarea" v-model="User.descri" maxlength="500"
                    show-word-limit placeholder="请输入问题" clearable></el-input>
        </el-col>
      </el-form-item>
      <el-form-item>
        <el-col :span="10" style="text-align: right">
          <el-button type="primary" @click="registerUsers()">录入</el-button>
        </el-col>
      </el-form-item>
    </el-form>
  </div>

</template>

<script>
    import {postRequest} from "../utils/api";

    export default {
        name: "InsertQuest",
        data() {
            return {
                User: {
                    descri: '',
                },
                login: {},
                questrules: {
                    descri: [{required: true, message: '问题描述不可为空', trigger: 'blur'}],
                },
            }
        },
        methods: {
            registerUsers() {
                this.$refs.User.validate((valid) => {
                    if (valid) {
                        postRequest(
                            '/Quest/register',
                            {
                                'username': this.login.username,
                                'descri': this.User.descri
                            }
                        ).then(res => {
                            // 密码修改校验成功
                            if (res && res.flag === '1') {
                                // 保存登录信息
                                this.$message.success(' 用户录入成功');
                                // replace 不可回退  铺设可以
                                //this.$router.push('/Login')
                            } else {
                                this.loading = false
                                // 修改失败
                                this.$message.error(res.msg + '!');
                            }
                        })
                    } else {
                        this.$message.warning('请完整规范填写自身修改信息！');
                        return false;
                    }
                })

            },
            getLoginInfo() {
                this.login = JSON.parse(this.$store.state.loginParam)
            }

        },
        mounted() {
            this.getLoginInfo()
        }
    }
</script>

<style scoped>

  element.style {
    min-height: 50px;
  }
</style>
